const Koa = require("koa");
const app = new Koa();

app.use(async (ctx, next) => {
    // cors
    ctx.set("Access-Control-Allow-Origin", "http://127.0.0.1:5500"); // 跨域
    ctx.set("Access-Control-Allow-Credentials", true); // 处理cookie
    ctx.set("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
    ctx.cookies.set("role", "superman1", {
        httpOnly: true,
    });
    console.log(ctx.cookies.get("role"));
    ctx.body = "我是super man";
});

app.listen(3000);
console.log("app started at port 3000...");
